package com.nbsaas.boot.example.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.CatalogEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import lombok.Data;

import javax.persistence.*;
import java.util.List;


@CatalogClass
@CreateByUser
@Data
@FormAnnotation(title = "案例分类管理", model = "案例分类", menu = "1,57,65")
@Entity
@Table(name = "bs_example_catalog")
public class ExampleCatalog extends CatalogEntity {


    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private ExampleCatalog parent;

    @FieldConvert
    @FieldName
    @ManyToOne(fetch = FetchType.LAZY)
    private User creator;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
    private List<ExampleCatalog> children;

    @Override
    public Long getParentId() {
        if (parent != null) {
            return parent.getId();
        }
        return null;
    }
}
